package com.lagou.service;

import com.lagou.TPMonitorFilter;
import org.apache.dubbo.config.annotation.Service;

import java.util.Random;
import java.util.concurrent.TimeUnit;

@Service
public class HelloServiceImpl implements HelloService {
    private Random rd = new Random();

    @Override
    public int methodA() {
        invoke();
        return 0;
    }

    @Override
    public int methodB() {
        invoke();
        return 1;
    }

    @Override
    public int methodC() {
        invoke();
        return 2;
    }

    private String invoke() {
        int sleep = rd.nextInt(TPMonitorFilter.DELAY_RANGE + 1);
        try {
            TimeUnit.MILLISECONDS.sleep(sleep);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return String.format("Sleep %d", sleep);
    }
}
